{% extends "base.html" %}

{% block content %}
    <h1>Hi, {{ current_user.username }}!</h1>

    <table border='1' style='margin-bottom: 20px;'>
        <th>User</th>
        <th>Suggestion</th>
        <th>Comments</th>
        <th>Votes</th>
        <th>Action</th>
        <col width='130px' />
        <col width='300px' />
        <col width='300px' />
        <col width='125px' />
        <col width='125px' />
    {% for suggestion in suggestions %}
    <tr>
            <td>
                {{ suggestion.author.username }} suggests:
            </td>
            <td>
                <strong>{{ suggestion.body }}</strong>
            </td>

            <td>
                {% if suggestion.comment != None %}
                {{ urlify(suggestion.comment)|safe }}
                {% endif %}
            </td>

            <td>
                {% if get_users_voted(suggestion.id) != '' %}
                Voted: {{ get_users_voted(suggestion.id) }}
                {% endif %}
            </td>

            {% if current_user.username != suggestion.author.username or current_user.username == admin %}
            <!-- if vote exist -->
                {% if exists_vote(current_user.id, suggestion.id) %}
            <td>
                    <form action='/unvote/{{ suggestion.author.username }}/{{ suggestion.id }}' method='post'>
                        <button style='width: 100%;' type='submit'> Unvote </button>
                    </form>
            </td>
                {% else %}
                <!-- else if vote not exists -->
            <td>
                    <form action='/vote/{{ suggestion.author.username }}/{{ suggestion.id }}' method='post'>
                        <button style='width: 100%;' type='submit'> Vote fot it! </button>
                    </form>
            </td>
                {% endif %}
            {% else %}
            <td>  </td>
            {% endif %}
    </tr>
    {% endfor %}
    </table>

    <form action='/add' method='POST'>
        Add something:
        <input type='text' name='name' placeholder='Suggestion name' />
        <input type='text' name='comment' placeholder='Comment (like links, reasons)' />
        <button type='submit'> Add </button>
    </form>
{% endblock %}


<!-- EOF -->

